const {
    getBannerApi,
    getRecommendApi
} = require("../../api/api")

let page = 1;
let finish = false;

Page({
    data: {
        list: [],
        recommendList: [],
        indicatorDots: true,
        vertical: false,
        autoplay: false,
        interval: 2000,
        duration: 500,
        value: ""
    },
    goDetail(e) {
        wx.navigateTo({
            url: '../detail/detail?id=' + e.target.dataset.id,
        })
    },
    onLoad() {
        // const res = await getBannerApi();
        // this.setData({
        //     list: res.result.list
        // })
        // Promise.all([getBannerApi(), getRecommendApi()]).then(res => {
        //     this.setData({
        //         list: res[0].result.list
        //     })
        //     console.log(res[1]);
        // })

        this.getBannerData();
        this.getRecommendData()
    },
    onReachBottom() {
        if (!finish) {
            console.log("拉到底了");
            this.getRecommendData();
        }

    },
    async getBannerData() {
        const res = await getBannerApi();
        this.setData({
            list: res.result.list
        })
    },
    async getRecommendData() {
        const res = await getRecommendApi({
            count: 3,
            page,
        });
        page++;
        
        this.setData({
            recommendList: [...this.data.recommendList, ...res.result.list],
        })
        if (res.result.list.length < 3) {
            finish = true
        }
    }
})